<?php

// no direct access

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class RoomBookingViewStatistics extends JView {

    /**
     * Booking view display method
     * @return void
     * */
    function display($tpl = null) {
        $items = & $this->get('Data');
        $month_num = 0;
        $val = '';
        $mon = '';
        $month = 0;
        $sum = 0;
        for ($i = 0, $n = count($items); $i < $n; $i++) {
            $row = & $items[$i];
            $m = substr($row->end, 5, 2);
            if($month == 0){
                $month = $m;
                $sum += $row->total;
            }else if($month == $m){
                $sum += $row->total;
            }else if($month != $m){
                if($val == '')$val .= $sum;
                else $val .= ','.$sum;
                if($mon == '')$mon .= (int)$month;
                else $mon .= ','.(int)$month;
                $month = $m;
                $sum = $row->total;
                $month_num += 1;
                if($month_num == 5)break;
            }
        }
        if($val == '')$val .= $sum;
        else $val .= ','.$sum;
        if($mon == '')$mon .= (int)$month;
        else $mon .= ','.(int)$month;
        $this->assignRef('val', $val);
        $this->assignRef('mon', $mon);
        parent::display($tpl);
    }

}
